import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_app/stateLearn/click_txt.dart';
import 'package:get/get.dart';
import 'package:get/get_rx/src/rx_types/rx_types.dart';

class HandSql<T> extends StatelessWidget {
  HandSql({Key? key, required this.handInfo, required this.hand})
      : super(key: key);
  final String handInfo;
  final Function(String userName,int age,int sex) hand;
  var userName = "";
  var userAge = 0;
  var sex = 1.obs;

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: const EdgeInsets.fromLTRB(0, 10, 0, 10),
      padding: const EdgeInsets.fromLTRB(10, 0, 10, 0),
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(12),
          border: Border.all(
            color: Colors.blue,
            width: 2,
          )
      ),
      child: Column(
        children: [
          TextField(
            onChanged: (value) {
              userName = value;
            },
            decoration: const InputDecoration(
                labelText: "姓名", labelStyle: TextStyle(color: Colors.red)),
          ),
          TextField(
            onChanged: (value) {
              print("输入值:$value");
              userAge = int.parse(value.isEmpty?"0":value);
            },
            inputFormatters: [FilteringTextInputFormatter.allow(RegExp("[0-9]"))],
            keyboardType: TextInputType.number,
            decoration: const InputDecoration(
                labelText: "年龄", labelStyle: TextStyle(color: Colors.red)),
          ),
          Row(
            children: <Widget>[
              Flexible(
                child: Obx(() {
                  return RadioListTile(
                      value: 1,
                      title: const Text("男"),
                      groupValue: sex.value,
                      onChanged: (value) {
                        sex.value = value == null ? 1 : 1;
                      });
                }),
              ),
              Flexible(
                child: Obx(() {
                  return RadioListTile(
                      value: 2,
                      title: const Text("女"),
                      groupValue: sex.value,
                      onChanged: (value) {
                        sex.value = value == null ? 2 : 2;
                      });
                }),
              )
            ],
          ),
          ClickTxt(
              info: handInfo,
              onPressed: ()=>hand(userName,userAge,sex.value)
              ),
        ],
      ),
    );
  }
}
